﻿#include "CircleWidget.h"
#include <QSize>
#include <QPainter>

CircleWidget::CircleWidget(QWidget *parent)
    : QWidget(parent),
      m_state(0)
{

}

void CircleWidget::paintEvent(QPaintEvent *event)
{
    QSize size = this->size();

    int min = qMin(size.width(), size.height());

    int center_x = size.width() / 2;
    int center_y = size.height() / 2;

    QPainter painter(this);
    QPen pen;
    pen.setWidth(2);
    painter.setPen(pen);
    painter.drawArc(QRectF(center_x - min / 2, center_y - min / 2, min, min),0, 360 * 16);
    if(m_state == 1)
    {
        painter.setBrush(Qt::red);
        painter.drawEllipse(QRectF(center_x - min / 2, center_y - min / 2, min, min));
    }
    else if(m_state == 2)
    {
        painter.setBrush(Qt::green);
        painter.drawEllipse(QRectF(center_x - min / 2, center_y - min / 2, min, min));
    }
}
